﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Operations.aspx.cs" Inherits="Patient_Operations" Title="Untitled Page" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<p>
    &nbsp;</p>
    <p>
    Регистрирайте избрания пациент като опериран:
        <asp:FormView ID="fvPatients" runat="server" DataKeyNames="PatientID" 
            DataSourceID="sdsPatients" BackColor="White" BorderColor="#E7E7FF" 
            BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <EditItemTemplate>
                PatientID:
                <asp:Label ID="PatientIDLabel1" runat="server" 
                    Text='<%# Eval("PatientID") %>' />
                <br />
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                MiddleName:
                <asp:TextBox ID="MiddleNameTextBox" runat="server" 
                    Text='<%# Bind("MiddleName") %>' />
                <br />
                LastName:
                <asp:TextBox ID="LastNameTextBox" runat="server" 
                    Text='<%# Bind("LastName") %>' />
                <br />
                EGN:
                <asp:TextBox ID="EGNTextBox" runat="server" Text='<%# Bind("EGN") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                MiddleName:
                <asp:TextBox ID="MiddleNameTextBox" runat="server" 
                    Text='<%# Bind("MiddleName") %>' />
                <br />
                LastName:
                <asp:TextBox ID="LastNameTextBox" runat="server" 
                    Text='<%# Bind("LastName") %>' />
                <br />
                EGN:
                <asp:TextBox ID="EGNTextBox" runat="server" Text='<%# Bind("EGN") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                <b>ЕГН:</b>
                <asp:Label ID="EGNLabel" runat="server" Text='<%# Bind("EGN") %>' />
                &nbsp; <b>Име:</b><asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
                &nbsp; <b>Презиме:</b>
                <asp:Label ID="MiddleNameLabel" runat="server" 
                    Text='<%# Bind("MiddleName") %>' />
                &nbsp;&nbsp; <b>Фамилия: </b>
                <asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' />
                <br />
            </ItemTemplate>
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        </asp:FormView>
        <br />

    </p>
    <p>
    &nbsp;Дата на операцията:<asp:TextBox ID="tbDate" runat="server"></asp:TextBox>
    <asp:Button ID="btnDate" runat="server" Text="..." />
    </p>
    <p>
    Допълнителна информация:<br />
    <asp:TextBox ID="txtNotes" runat="server" Height="95px" 
            TextMode="MultiLine" Width="767px"></asp:TextBox>
                          <ajax:CalendarExtender ID="ceCalendar" PopupButtonID="btnDate" TargetControlID="tbDate"
                            runat="server">
                        </ajax:CalendarExtender>
    &nbsp;<asp:Button ID="btnAdd" runat="server" Text="Добави" onclick="btnAdd_Click" />
    </p>
    <asp:GridView ID="gvOperations" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="OperationID" 
        DataSourceID="sdsOperations">
        <Columns>
            <asp:CommandField DeleteText="Изтриване" EditText="Промяна" 
                ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="EGN" HeaderText="ЕГН" SortExpression="EGN" />
            <asp:BoundField DataField="Name" HeaderText="Име" 
                SortExpression="Name" />
            <asp:BoundField DataField="MiddleName" HeaderText="Презиме" 
                SortExpression="MiddleName" />
            <asp:BoundField DataField="LastName" HeaderText="Фамилия" 
                SortExpression="LastName" />
            <asp:BoundField DataField="Date" HeaderText="Дата" SortExpression="Date" />
            <asp:BoundField DataField="Notes" HeaderText="Бележки" SortExpression="Notes" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="sdsOperations" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ClinicConnectionString %>" 
        DeleteCommand="DELETE FROM [Operations] WHERE [OperationID] = @OperationID" 
        InsertCommand="INSERT INTO [Operations] ([PatientID], [Date], [Notes]) VALUES (@PatientID, @Date, @Notes)" 
        SelectCommand="SELECT Operations.OperationID, Operations.Date, Operations.Notes, Patients.EGN, Patients.Name, Patients.MiddleName, Patients.LastName FROM Operations INNER JOIN Patients ON Operations.PatientID = Patients.PatientID" 
        
        UpdateCommand="UPDATE [Operations] SET [PatientID] = @PatientID, [Date] = @Date, [Notes] = @Notes WHERE [OperationID] = @OperationID">
        <DeleteParameters>
            <asp:Parameter Name="OperationID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="PatientID" Type="Int32" />
            <asp:Parameter Name="Date" Type="DateTime" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="OperationID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:QueryStringParameter Name="PatientID" QueryStringField="PatientID" 
                Type="Int32" />
            <asp:ControlParameter ControlID="tbDate" Name="Date" PropertyName="Text" 
                Type="DateTime" />
            <asp:ControlParameter ControlID="txtNotes" Name="Notes" PropertyName="Text" 
                Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsPatients" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ClinicConnectionString %>" 
        
        SelectCommand="SELECT [PatientID], [Name], [MiddleName], [LastName], [EGN] FROM [Patients] WHERE ([PatientID] = @PatientID)" 
        UpdateCommand="UPDATE Operations SET Date = @Date, Notes = @Notes WHERE (PatientID = @PatientID)">
        <SelectParameters>
            <asp:QueryStringParameter Name="PatientID" QueryStringField="PatientID" 
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <br />
    
</asp:Content>

